<?php

namespace App\Models;

use Jenssegers\Mongodb\Eloquent\Model;

class Shelve extends Model
{
    protected $connection = 'mongodb';
    protected $collection = 'xcx_shelve';
    public $timestamps = false;

    /**
     * 执行管道查询
     *
     * @param array $pipeline
     * @return \Illuminate\Support\Collection
     */
    public static function aggregate($pipeline)
    {
        return self::raw(function ($collection) use ($pipeline) {
            return $collection->aggregate($pipeline, ['allowDiskUse' => true]);
        });
    }

    /**
     * 创建索引
     *
     * @return void
     */
    public static function createIndexes()
    {
        self::raw(function ($collection) {
            $collection->createIndex(['shelve_no' => 1]); // 创建升序索引
        });
    }
}
